package com.longge;

import java.util.Stack;

public class CanSeePersonsCount {

    public int[] canSeePersonsCount(int[] heights) {

        Stack<Integer> stack = new Stack<>();
        int[] res = new int[heights.length];
        for (int i = heights.length - 1; i >= 0; i--) {
            while (!stack.isEmpty() && stack.peek() < heights[i]) {
                stack.pop();
                res[i]++;
            }

            while (!stack.isEmpty()) {
                res[i]++;
            }
            stack.push(heights[i]);

        }
        return res;


    }


}
